//
//  GDTAdDeleget.m
//  shortvideoplay
//
//  Created by tikeios_002 on 2024/8/14.
//

#import "GDTAdDeleget.h"
#import "CSJADLoading.h"
@interface GDTAdDeleget ()

@end
@implementation GDTAdDeleget
+ (instancetype)share {
    static GDTAdDeleget *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[GDTAdDeleget alloc] init];
    });
    return manager;
}
- (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error{
    if([CSJADLoading share].ADNativeAdsLoadFish){
        [CSJADLoading share].ADNativeAdsLoadFish(nil,0);
    }
}
-(void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd *)nativeExpressAd views:(NSArray<__kindof GDTNativeExpressAdView *> *)views{
    if([CSJADLoading share].ADNativeAdsLoadFish){
        [CSJADLoading share].ADNativeAdsLoadFish(views,1);
    }
}
- (void)nativeExpressAdView:(GDTNativeExpressAdView *)nativeExpressAdView playerStatusChanged:(GDTMediaPlayerStatus)status{
    if(status == GDTMediaPlayerStatusStarted){
        NSLog(@"开始播放");
//        static dispatch_once_t onceToken;
//        dispatch_once(&onceToken, ^{
//           NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateCurrentPlayedTime) userInfo:nil repeats:YES];
//            [timer fire];
//        });
        
        if(![[QZUserInfoModel share].adSaveFishArr containsObject:[QZUserInfoModel share].adPlayId]){
            [[QZHongBaoView share] stopClick:YES];
        }
    }else{
        NSLog(@"结束播放%f===%ld",nativeExpressAdView.videoPlayTime,(long)nativeExpressAdView.videoDuration);
        [[QZHongBaoView share] stopClick:NO];
        if(nativeExpressAdView.videoDuration - nativeExpressAdView.videoPlayTime < 1 ){
            if(![[QZUserInfoModel share].adSaveFishArr containsObject:[QZUserInfoModel share].adPlayId]){
                [[QZUserInfoModel share].adSaveFishArr addObject:[QZUserInfoModel share].adPlayId];
                
            }
            if([CSJADLoading share].ADNativeAdsLoadPlayFish){
                [CSJADLoading share].ADNativeAdsLoadPlayFish(YES);
            }
        }
    }
}
/**
 * 原生模板广告曝光回调
 */
- (void)nativeExpressAdViewExposure:(GDTNativeExpressAdView *)nativeExpressAdView{
    NSLog(@"=====nativeExpressAdView奖励%ld",nativeExpressAdView.eCPM);
}

/**
 * 原生模板广告点击回调
 */
- (void)nativeExpressAdViewClicked:(GDTNativeExpressAdView *)nativeExpressAdView{
    NSLog(@"=====nativeExpressAdView奖励%ld",nativeExpressAdView.eCPM);
}

@end
